#define _CRT_SECURE_NO_WARNINGS 1
#include"Head.h"
class Solution {
public:
    int minOperations(vector<int>& nums, int x) {
        int left = 0, right = 0;
        int target = 0, sum = 0, len = -1;
        for (int num : nums)
            target += num;
        target -= x;
        if (target < 0) return -1;
        while (right < nums.size())
        {
            sum += nums[right];
            while (sum > target)
            {
                sum -= nums[left++];
            }
            if (sum == target)
            {
                len = max(len, right - left + 1);
            }
            right++;
        }
        return len == -1 ? -1 : nums.size() - len;
    }
};
int main()
{
    Solution s;
    vector<int> v{ 1,1 };
    cout<<s.minOperations(v,3) << endl;
    return 0;
}